package com.yyplatform.admin.platform.init.data;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.yyplatform.admin.platform.generator.controller.CodeGenController;
import com.yyplatform.admin.platform.generator.controller.ColumnConfigController;
import com.yyplatform.admin.platform.generator.controller.TableConfigController;
import com.yyplatform.admin.platform.notice.controller.SysNoticeUserController;
import com.yyplatform.admin.platform.role.model.entity.SysMenuEntity;
import com.yyplatform.admin.platform.role.model.enums.MenuTypeEnum;
import com.yyplatform.admin.platform.role.repository.SysMenuRepository;
import com.yyplatform.admin.platform.role.service.SysMenuService;

/**
 * @author sleepforests@163.com
 * <p>
 * Created on 2024/11/16 20:42
 */

public class InitMenuData4Dev {

    private SysMenuRepository sysMenuRepository;

    private SysMenuService sysMenuService;

    public InitMenuData4Dev(SysMenuRepository sysMenuRepository1, SysMenuService sysMenuService1) {
        sysMenuRepository = sysMenuRepository1;
        sysMenuService = sysMenuService1;
    }


    public void init() {
        String name = "开发工具";


        SysMenuEntity menu = new SysMenuEntity();
        menu.setAlwaysShow(true);
        menu.setComponent("Layout");
        menu.setEnabled(true);
        menu.setIcon("code");
        menu.setKeepAlive(true);
        menu.setName(name);
        menu.setOrderNum(100);
        menu.setParams(Collections.emptyList());
        menu.setPermissions("");
        menu.setPid(0L);
        menu.setRedirect("");
        menu.setRemark("");
        menu.setRouteName("");
        menu.setRoutePath("/dev");
        menu.setVisible(true);

        menu.setMenuType(MenuTypeEnum.MENU_TYPE_FOLDER.getValue());

        sysMenuRepository.save(menu);

        test_init_开发工具_代码生成(menu);

        test_init_服务监控(menu);
        test_init_缓存监控(menu);


        test_init_开发工具_接口文档(menu);
        test_init_开发工具_SQL监控(menu);

    }


    //    @Test
    public void test_init_开发工具_代码生成(SysMenuEntity menuRoot) {


        long id = 0;

        SysMenuEntity menu = new SysMenuEntity();
        menu.setAlwaysShow(false);
        menu.setComponent("platform/tableConfig/index");
        menu.setEnabled(true);
        menu.setIcon("code");
        menu.setKeepAlive(true);
        menu.setName("代码生成");
        menu.setOrderNum(100);
        menu.setParams(Collections.emptyList());
        menu.setPermissions("sys:tableConfig:query");
        menu.setPid(menuRoot.getId());
        menu.setRedirect("");
        menu.setRemark("");
        menu.setRouteName("TableConfig");
        menu.setRoutePath("platform/tableConfig/index");
        menu.setVisible(true);

        menu.setMenuType(MenuTypeEnum.MENU_TYPE_MENU.getValue());

        sysMenuRepository.save(menu);

        id = menu.getId();


        List<String> list2 = new ArrayList<>();
        list2.add(TableConfigController.class.getName());
        list2.add(ColumnConfigController.class.getName());
        list2.add(CodeGenController.class.getName());


        sysMenuService.saveBatchByControllerName(id, list2);
    }


    //    @Test
    public void test_init_开发工具_接口文档(SysMenuEntity menuRoot) {


        SysMenuEntity menu = new SysMenuEntity();
        menu.setAlwaysShow(false);
        menu.setComponent("platform/apiDoc/index");
        menu.setEnabled(true);
        menu.setIcon("api");
        menu.setKeepAlive(true);
        menu.setName("接口文档");
        menu.setOrderNum(100);
        menu.setParams(Collections.emptyList());
        menu.setPermissions("");
        menu.setPid(menuRoot.getId());
        menu.setRedirect("");
        menu.setRemark("");
        menu.setRouteName("ApiDoc");
        menu.setRoutePath("http://localhost:8081/doc.html");
        menu.setVisible(true);

        menu.setMenuType(MenuTypeEnum.MENU_TYPE_LINK.getValue());

        sysMenuRepository.save(menu);


    }


    //    @Test
    public void test_init_开发工具_SQL监控(SysMenuEntity menuRoot) {


        SysMenuEntity menu = new SysMenuEntity();
        menu.setAlwaysShow(false);
        menu.setComponent("platform/sqlMonitor/index");
        menu.setEnabled(true);
        menu.setIcon("el-icon-Coin");
        menu.setKeepAlive(true);
        menu.setName("SQL监控");
        menu.setOrderNum(100);
        menu.setParams(Collections.emptyList());
        menu.setPermissions("");
        menu.setPid(menuRoot.getId());
        menu.setRedirect("");
        menu.setRemark("");
        menu.setRouteName("");
        menu.setRoutePath("http://localhost:8081/druid/datasource.html");
        menu.setVisible(true);

        menu.setMenuType(MenuTypeEnum.MENU_TYPE_LINK.getValue());

        sysMenuRepository.save(menu);


    }

    private void test_init_服务监控(SysMenuEntity rootMenu) {


        long id = 0;

        SysMenuEntity menu = new SysMenuEntity();
        menu.setAlwaysShow(false);
        menu.setComponent("platform/monitorServer/index");
        menu.setEnabled(true);
        menu.setIcon("table");
        menu.setKeepAlive(true);
        menu.setName("服务监控");
        menu.setOrderNum(100);
        menu.setParams(Collections.emptyList());
        menu.setPermissions("sys:monitorServer:query");
        menu.setPid(rootMenu.getId());
        menu.setRedirect("");
        menu.setRemark("");
        menu.setRouteName("MonitorServer");
        menu.setRoutePath("platform/monitorServer/index");
        menu.setVisible(true);

        menu.setMenuType(MenuTypeEnum.MENU_TYPE_MENU.getValue());

        sysMenuRepository.save(menu);

        id = menu.getId();


        List<String> list2 = new ArrayList<>();
        list2.add(SysNoticeUserController.class.getName());
        sysMenuService.saveBatchByControllerName(id, list2);
    }

    private void test_init_缓存监控(SysMenuEntity rootMenu) {

        long id = 0;

        SysMenuEntity menu = new SysMenuEntity();
        menu.setAlwaysShow(false);
        menu.setComponent("platform/monitorCache/index");
        menu.setEnabled(true);
        menu.setIcon("table");
        menu.setKeepAlive(true);
        menu.setName("缓存监控");
        menu.setOrderNum(100);
        menu.setParams(Collections.emptyList());
        menu.setPermissions("sys:monitorCache:query");
        menu.setPid(rootMenu.getId());
        menu.setRedirect("");
        menu.setRemark("");
        menu.setRouteName("MonitorCache");
        menu.setRoutePath("platform/monitorCache/index");
        menu.setVisible(true);

        menu.setMenuType(MenuTypeEnum.MENU_TYPE_MENU.getValue());

        sysMenuRepository.save(menu);

        id = menu.getId();


        List<String> list2 = new ArrayList<>();
        list2.add(SysNoticeUserController.class.getName());
        sysMenuService.saveBatchByControllerName(id, list2);
    }


}



